Support expressions in confirm attribute#3201
Conversation
casey
left a comment
There was a problem hiding this comment.
Thanks for the PR! Left some comments.
| loop { | ||
| let name = self.parse_name()?; | ||
|
|
||
| let mut arguments = Vec::new(); |
There was a problem hiding this comment.
Parsing attributes is complex enough that I'd like to avoid this duplication. Can we always parse an expression, and then just complain if the expression is not a string literal unless it's the confirm attribute? That would avoid the duplication, and additionally make it easy to start accepting expressions in other attributes in the future.
|
|
||
| let mut evaluator = Evaluator::new(&context, BTreeMap::new(), true, &scope); | ||
|
|
||
| if !config.yes && !recipe.confirm(&mut evaluator)? { |
There was a problem hiding this comment.
Hmmmmmmm, I kind of don't like that we now have to evaluate the parameters before we confirm that we want to run the recipe. This is a change in behavior. I think it's acceptable though, since there is probably not much going on in parameters expressions.
src/attribute.rs
Outdated
| } | ||
| } | ||
|
|
||
| impl Eq for Attribute<'_> {} |
The confirmation prompt accepts any expression, so you can use variables,
concatenation, and function calls:
Recipe parameters can also be used in confirmation prompts: